<template>
  <div :id="id" :class="className" :style="{height:height,width:width}" />
</template>

<script>
import resize from "./mixins/resize";

export default {
  props: {
    className: {
      type: String,
      default: "chart"
    },
    id: {
      type: String,
      default: "chart"
    },
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "200px"
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      this.setOptions(this.chartData);
    },
    setOptions({ DayData } = {}) {
      this.chart.setOption({
        // 悬浮显示
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          orient: "vertical",
          top: "middle",
          bottom: 10,
          top: 100,
          right: 20,
          left: "right",
          data: ["当前在线", "当前离线"],
          textStyle: {
            color: "#e6e6e6"
          }
        },
        color: ["#308e92", "#ef5055"],
        series: [
          {
            name: "设备信息",
            type: "pie",
            radius: "65%",
            center: ["30%", "50%"],
            // 隐藏标识线、文字
            itemStyle: {
              normal: {
                label: {
                  show: false
                },
                labelLine: {
                  show: false
                }
              }
            },
            data: [
              { value: 24, name: "当前在线" },
              { value: 2, name: "当前离线" }
            ]
          }
        ],
        // 扇区大小不一效果
        // roseType: "radius"
      });
    }
  }
};
</script>